
open Gero;;
open Unix;;
open Bigarray;;
open Thread;;


let mlMain n m=
  Random.self_init();
  let vec1 =  Gero.create floats32 n
  and vec2 =  Gero.create floats32 n
  and vec3 =  Gero.create floats32 n
  and res2 = ref (Gero.create floats32 n) in
  (
  
  	for i = 0 to n-1 do	
			Gero.set vec1 i (Random.float 32.0);
			Gero.set vec2 i (Random.float 32.0);
			Gero.set vec3 i (Random.float 32.0);
	  done;
  	Printf.printf "SPE Utilisables : %d\n" (spe_count_usable_spes ());
  	flush Pervasives.stdout;
  	let t1 = Unix.times () in
		(
			for i =0 to m do
  			res2 := Gero.fmaf4_spu vec1 vec2 vec3;   
  		done;
  		let t2 = Unix.times () in
  		(
   		for i=0 to 16 do 
				(
			  	 Printf.printf "vec1[%d] : %f * vec2[%d] : %f + vec3[%d] : %f = a[%d] : %f \n" i (Gero.get vec1 i) i (Gero.get vec2 i) i (Gero.get vec3 i) i (Gero.get !res2 i);
			  	 flush Pervasives.stdout;
			  ) 
			done;
			Printf.printf "Temps AltiVec SPU: System Time; %f, User Time:%f \n" ((t2.tms_stime)-.(t1.tms_stime)) ((t2.tms_utime)-.(t1.tms_utime));
			)
		)
	)
;;


mlMain (int_of_string (Sys.argv.(1))) (int_of_string (Sys.argv.(2)));
;;
